var domain = getRootPath();
var curruntCity = getCookie("localcitycode");
var localCity = unescape(getCookie("localcity"));

if (curruntCity==''||localCity==''||curruntCity==null||localCity==null||curruntCity=="undefined"||localCity=="undefined"||typeof(localCity)=="undefined"||typeof(curruntCity)=="undefined") {
	curruntCity = '500100';
	localCity = '重庆市';
	var myCity = new BMap.LocalCity();
	myCity.get(myFun);
	
}


function myFun(result) {
	var cityName = result.name;

	myAjax(domain + '/getPlaceByName.do', {"PlaceName":cityName
	}, function(data) {
		
		document.cookie = "localcitycode=" + data.daima + ";expires=" + "-1";
		document.cookie = "localcity=" + escape(cityName) + "" + ";expires="
				+ "-1";
		curruntCity = data.daima;
		localCity = cityName;
	
		window.location.reload();
	});
         
}

function getCookie(name) {

	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	if (arr = document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;
}
function setFormValidate($form) {
	var $tooltip = $('<div id="tooltip">提示信息！</div>');
	$tooltip.appendTo(document.body);
	$form.validator({
		onValid : function() {
			$tooltip.hide()
		}
	});
	$form.on('focusin focusout', '.am-form-error input', function(e) {
		if (e.type === 'focusin') {
			var $this = $(this);
			var offset = $this.offset();
			var msg = $this.data('foolishMsg')
					|| $form.validator("getValidationMessage", $this
							.data("validity"));

			$tooltip.text(msg).show().css({
				left : offset.left + 10,
				top : offset.top + $(this).outerHeight() + 10
			});
		} else {
			$tooltip.hide();

		}
	});
}
function drawPages($ul, currentpage, pages, pagesize) {
	$ul.empty();
	if (pages === 1) {
		currentpage = 1;
		$ul
				.append('<li class="am-pagination-first"> <a onclick="changepage(this)" class="firstpage" href=\"#\" >第一页</a> </li>');
		$ul
				.append('<li class="am-active">  <a href=\"#\" onclick="changepage(this)" class=\"am-active\">1</a> </li>');
		$ul
				.append('<li class="am-pagination-last "><a onclick="changepage(this)"  class="endpage"  href="#" >最末页</a> </li>');
	}

	else if (pages <= pagesize) {

		$ul
				.append('<li class=\"am-pagination-first \"> <a href="#" onclick="changepage(this)" class="firstpage"  >第一页</a> </li>');
		if (currentpage > 1)
			$ul
					.append(' <li class=\"am-pagination-prev \"> <a onclick="changepage(this)" href="#" class="beforepage">上一页</a></li>');
		for (i = 1; i <= pages; i++) {
			if ((i) == currentpage) {

				$ul
						.append('<li class=\"am-active\">  <a href="#"  onclick="changepage(this)" class=\"am-active\">'
								+ i + '</a> </li>');

			} else
				$ul
						.append('<li > <a href="#" onclick="changepage(this)" class="notactive" >'
								+ i + '</a> </li>');
		}
		if (currentpage <= pages - 1)
			$ul
					.append(' <li class=\"am-pagination-prev \"> <a href="#" onclick="changepage(this)"  class="lastpage">下一页</a></li>');
		$ul
				.append('<li class=\"am-pagination-last \"><a href="#"  onclick="changepage(this)" class="endpage"  >最末页</a> </li>');
	} else if (pages > pagesize) {
		$ul
				.append('<li class=\"am-pagination-first \"> <a href="#" onclick="changepage(this)" class="firstpage"  >第一页</a> </li>');
		if (currentpage > 1)
			$ul
					.append(' <li class=\"am-pagination-prev \"> <a onclick="changepage(this)" href="#" class="beforepage">上一页</a></li>');
		if ((pages - currentpage) >= pagesize) {

			for (i = currentpage; i <= pages; i++)
				if ((i) === currentpage)
					$ul
							.append('<li class=\"am-active\">  <a href="#"  onclick="changepage(this)" class=\"am-active\">'
									+ i + '</a> </li>');
				else {
					if ((i) > pages || (i - currentpage >= 5))
						break;
					$ul
							.append('<li > <a href="#" onclick="changepage(this)" class="notactive" >'
									+ (i) + '</a> </li>');
				}
		} else {
			for (i = pages - 4; i <= pages; i++)
				if ((i) === currentpage)
					$ul
							.append('<li class=\"am-active\">  <a href="#"  onclick="changepage(this)" class=\"am-active\">'
									+ i + '</a> </li>');
				else {
					if ((i) > pages)
						break;
					$ul
							.append('<li > <a href="#" onclick="changepage(this)" class="notactive" >'
									+ (i) + '</a> </li>');
				}
		}
		if (currentpage <= pages - 1)
			$ul
					.append(' <li class=\"am-pagination-prev \"> <a href="#" onclick="changepage(this)"  class="lastpage">下一页</a></li>');
		$ul
				.append('<li class=\"am-pagination-last \"><a href="#"  onclick="changepage(this)" class="endpage"  >最末页</a> </li>');

	}

}

function myAjax(requesturl, data, fsuccess) {

	$.ajax({
		url : requesturl, // 请求的url地址
		dataType : "json",
		async : true,
		data : data,
		type : "POST",
		beforeSend : function() {
		},
		success : fsuccess,
		complete : function() {
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {

			if (errorThrown == 'Forbidden') {
				window.location.href = domain + '/Login.jsp';
				myAlert('提示', '登录失效，请重新登陆！！！');
			}else
				myAlert('提示', '服务器错误，请稍后再试！！！');
		}
	});
}

function getPlaceList(url, id, parameter, selected) {
	myAjax(url, parameter, function(data) {
		if (data != null) {
			if (selected == '')
				selected = data[0].daima;
			$.each(data, function(index, item) {

				if (selected == item.daima)
					$('#' + id).append(
							'<option value="' + item.daima
									+ '"selected="selected">' + item.diming
									+ '</option>');
				else
					$('#' + id).append(
							'<option value="' + item.daima + '" >'
									+ item.diming + '</option>');
			});
		}
	});
}
function appendCity() {
	$('#city').empty();
	$('#contry').empty();
	$('#city')
			.append(
					'<select id="s_city" name="s_city" class="am-inline"'
							+ 'style="width: 15%" onchange="changecity(this)"   onclick="changeplace(this)"></select>&nbsp;&nbsp;');
}
function appendContry() {
	$('#contry').empty();
	$('#contry')
			.append(
					'<select id="s_county" name="s_county" class="am-inline"'
							+ 'style="width: 15%" onchange="changecity(this)"  onclick="changeplace(this)" required></select>');
}

function changeplace(select) {

	if (select.id == 's_province') {
		appendCity();
		getPlaceList(domain + '/getCities.do', 's_city', {
			'Province' : $('#s_province').val()
		}, '');

	} else if (select.id == 's_city') {
		appendContry();
		getPlaceList(domain + '/getCountries.do', 's_county', {
			'City' : $('#s_city').val()
		}, '');
	}
}
function myPost(url, params) {
	var temp = document.createElement("form");
	temp.action = url;
	temp.method = "post";
	temp.style.display = "none";
	for ( var x in params) {
		var opt = document.createElement("textarea");
		opt.name = x;
		opt.value = params[x];
		temp.appendChild(opt);
	}
	document.body.appendChild(temp);
	temp.submit();
	return temp;
}

function drawEEContent($pagecontainer, data) {

	$.each(
					data,
					function(i, item) {
						index = item.id;
						$pagecontainer
								.append('<div class="am-panel am-panel-default ptinfo" id=ptinfo'
										+ (i)
										+ ''

										+ '><div class="am-panel-bd"><div class="am-g" '

										+ '>'
										+ ' <div class="am-u-lg-2 am-hide-md-down"><img src='
										+ item.logo
										+ ' style="height:80px;"></div>'
										+ ' <div class="am-u-lg-10"> <div class="am-g "><div class=" am-u-lg-7"><div class="am-g ">'

										+ ' <div class="am-u-lg-12 "   style="font-size:22px; color:#006699;"><a>'
										+ item.title
										+ '</a></div>'
										+ ' <div  class="am-u-lg-8"  style="font-size:12px; color:#999999;">工作时间：'
										+ item.begindate
										+ '~'
										+ item.enddate
										+ "&nbsp;&nbsp;"
										+ item.timebegin
										+ '~'
										+ item.timeend
										+ '</div> <div  class="am-u-lg-4 am-u-end"  style="font-size:12px; color:#999999;">兼职类型：'
										+ item.pttypeid
										+ '</div>  <div class="am-u-lg-4 " style="font-size:12px; color:#999999;">工作地点：'
										+ item.cityid
										+ ' </div>  <div class="am-u-lg-5 am-u-end" style="font-size:12px; color:#999999;">招聘人数：'
										+item.confirmed+'/'+item.personnum
										+ '人</div></div>'
										+ '</div>'
										+ '     <div class=" am-u-lg-3 " style="margin-top:26px; font-size:14px; color:#999999;">'
										+ item.salary
										+ '元 /'
										+ item.salaryunit
										+ ' '
										+ item.billcycleid
										+ '  </div>'
										+ ' <div class="am-u-lg-2 am-u-end"><button type="button" id=jobsubmit'
										+ i
										+ '  class="am-btn am-btn-warning jobsubmit" style="margin-top:20px;">我要报名</button></div></div></div></div>');

					});

}

function placeInit() {
	var reg = /[0-9]{6}/;
	if (!reg.test(curruntCity))
		curruntCity = '510100';
	else {
		getPlaceList(domain + '/getProvince.do', 's_province', {}, curruntCity
				.substring(0, 2)
				+ "0000");

		appendCity();
		getPlaceList(domain + '/getCities.do', 's_city', {
			'Province' : curruntCity.substring(0, 2) + "0000"
		}, curruntCity.substring(0, 4) + "00");
		appendContry();
		getPlaceList(domain + '/getCountries.do', 's_county', {
			'City' : curruntCity.substring(0, 4) + "00"
		}, '');
	}

}

function drowERContent($pagecontainer, data) {
	$
			.each(
					data,
					function(i, item) {
						index = item.id;

						$pagecontainer
								.append('<div class="am-panel am-panel-default" '

										+ '><div class="am-panel-bd"><div class="am-g" '

										+ '>'
										+ ' <div class="am-u-lg-2 am-hide-md-down"><img src='
										+ item.logo
										+ ' style="height:80px;"></div>'
										+ ' <div class="am-u-lg-10"> <div class="am-g "><div class=" am-u-lg-7"><div class="am-g ">'

										+ ' <div class="am-u-lg-12" style="font-size:22px; color:#006699;">'
										+ item.title
										+ '</div>'
										+ ' <div  class="am-u-lg-8"  style="font-size:12px; color:#999999;">工作时间：'
										+ item.begindate
										+ '~'
										+ item.enddate
										+ "&nbsp;&nbsp;"
										+ item.timebegin
										+ '~'
										+ item.timeend
										+ '</div> <div  class="am-u-lg-4 am-u-end"  style="font-size:12px; color:#999999;">兼职类型：'
										+ item.pttypeid
										+ '</div>  <div class="am-u-lg-4 " style="font-size:12px; color:#999999;">工作地点：'
										+ item.cityid
										+ ' </div>  <div class="am-u-lg-4 am-u-end" style="font-size:12px; color:#999999;">招聘人数：'
										+ item.personnum
										+ '人</div></div>'
										+ '</div>'
										+ '     <div class=" am-u-lg-3 " style="margin-top:26px; font-size:14px; color:#999999;">'
										+ item.salary
										+ '元 /'
										+ item.salaryunit
										+ ' '
										+ item.billcycleid

										+ '  </div>'
										+ '<div class="am-u-lg-2 am-u-end" > <div class="am-dropdown" id=choice'
										+ i
										+ ' data-am-dropdown><button onclick="buttontoggle(this,'
										+ i
										+ ')"  class="am-btn am-btn-default am-btn-sm am-dropdown-toggle am-btn-success" style="margin-top:20px;" data-am-dropdown-toggle><span class="am-icon-cog"></span> <span class="am-icon-caret-down"></span></button><ul  class="am-dropdown-content"><li id=edit'
										+ i
										+ ' class="edit"><a href=#'

										+ '>1. 编辑</a></li><li id=del'
										+ i
										+ ' class="del"><a href=#'
										+ '>2 删除</a></li><li  id=start'
										+ i
										+ ' class="start"><a   href=#'
										+ '>3. 开始报名</a></li> </ul> </div></div> '
										+ '</div></div></div>');
					});

}

function buttontoggle(button, dropdown) {

	$dropdown = $('#choice' + dropdown);

	$dropdown.dropdown('toggle');
	// alert(dropdown);
	return false;
}
function ptaddress(lat, lng, address, countrycode, detailAddress, isdel) {
	this.lat = lat;
	this.lng = lng;
	this.address = address;
	this.countrycode = countrycode;
	this.detailAddress = detailAddress;
	this.isdel = isdel;
}
function ptime(starthour, startmin, endhour, endmin, isdel) {
	this.starthour = starthour;
	this.startmin = startmin;
	this.endhour = endhour;
	this.endmin = endmin;
	this.isdel = isdel;
}
function drawmodal(obj, data) {
	var temp = '<h3>用户名</h3><p>' + data.username + '</p><hr><h3>专业</h3><p>'
			+ data.major + '</p>	<hr>'

			+ '<h3>工作宣言</h3><p>' + data.tellus + '</p><hr><h3>联系方式</h3><p>手机:'
			+ data.mobile + '</p><p>邮箱:' + data.email + '</p><p>微信:'
			+ data.wechatid + '</p>';

	obj.empty();
	obj
			.append(' <div data-am-widget="intro" class="am-intro am-cf am-intro-default">'

					+ '<div class="am-intro-hd"> <h2 class="am-intro-title">个人信息</h2><a class="am-intro-more am-intro-more-top " href="#">更多细节</a>  </div>'
					+ '<div class="am-g am-intro-bd">'
					// + '<div class="am-intro-left am-u-sm-5"></div>'
					// + '<div class="am-intro-right am-u-sm-7"></div>'
					+ temp + ' </div>' + '</div>');

}

function drawDiffStatusContent($pagecontainer, data, parameters) {
	var temp = '';
	$.each(
					data,
					function(i, item) {
						var index = item.id;
						if (parameters.status == 27) {
							temp = '<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">'
									+ ' <button id=edit'
									+ i
									+ ' class=" edit am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 编辑</button>'
									+ '  <button id=del'
									+ i
									+ ' class="del am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 删除</button>'
									+ ' <button   id=start'
									+ i
									+ ' class="am-btn start am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 开始报名</button>'
									+ ' </div> </div></td>'

						} else if (parameters.status == 28) {
							temp = '<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">'
									+ ' <button id=pay'
									+ i
									+ ' class=" pay am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 工资结算</button>'
									+ '  <button id=ReqManager'
									+ i
									+ ' class="ReqManager am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 报名管理</button>'
									+ ' <button   id=cancel'
									+ i
									+ ' class="am-btn cancel am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 结束报名</button>'
									+ ' </div> </div></td>'

						} else if (parameters.status == 29) {
							temp = '<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">'
									+ ' <button id=view'
									+ i
									+ ' class=" view am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 查看</button>'
									+ '  <button id=del'
									+ i
									+ ' class="del am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 删除</button>'
									+ ' <button   id=restart'
									+ i
									+ ' class="am-btn restart am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 再次报名</button>'
									+ ' </div> </div></td>'

						}
						$pagecontainer
								.append(' <tr class="ptjob" id=ptjob'+i+'><td><input type="checkbox" id=check'+i+' class=check value='
										+ i 
										+ '></td><td>'
										+ (i + 1)
										+ '</td><td>'
										+ item.title
										+ '</td><td>'
										+ item.salary
										+ '元/'
										+ item.salaryunit
										+ '</td><td>'+item.pttypeid+'</td><td>'+item.begindate+'~'+item.enddate+'</td> <td>'
										+ item.createtime
										+ '</td>'
										+ temp
										+ '</tr>');

					});

}
function drawDiffStatusContentend($pagecontainer, data, parameters) {
	var temp = '';
	$.each(
					data,
					function(i, item) {
						var index = item.id;
				
							temp = '<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">'
									+ ' <button id=pay'
									+ i
									+ ' class=" pay am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 工资结算</button>'
									+ '  <button id=ReqManager'
									+ i
									+ ' class="ReqManager am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 报名管理</button>'	
									+ ' </div> </div></td>'

						$pagecontainer
								.append(' <tr class="ptjob" id=ptjob'+i+'><td>'
										+ (i + 1)
										+ '</td><td>'
										+ item.title
										+ '</td><td>'
										+ item.salary
										+ '元/'
										+ item.salaryunit
										+ '</td><td>'+item.pttypeid+'</td><td>'+item.begindate+'~'+item.enddate+'</td> <td>'
										+ item.createtime
										+ '</td>'
										+ temp
										+ '</tr>');

					});

}
function drawdiffreqcontent($pagecontainer, parameters, data) {
	var temp = '';
	$
			.each(
					data,
					function(i, item) {
						var index = item.id;
						if (parameters.status == 30) {
							temp = '<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">'
									+ '  <button id=show'
									+ i
									+ ' class="show am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 查看</button>'
									+ ' <button   id=cancelreq'
									+ i
									+ ' class="am-btn cancelreq am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 取消报名</button>'
									+ ' </div> </div></td>'

						} else if (parameters.status == 31) {
							temp = '<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">'
									+ ' <button id=agreereq'
									+ i
									+ ' class=" agreereq am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span>  工资结算</button>'
									+ '  <button id=show'
									+ i
									+ ' class="show am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 查看</button>'
								
									+ ' </div> </div></td>'

						} else if (parameters.status == 35) {

							temp = '<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">'
									+ '  <button id=show'
									+ i
									+ ' class="show am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 查看</button>'
									+ ' <button   id=del'
									+ i
									+ ' class="am-btn del am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 删除</button>'
									+ ' </div> </div></td>'
						}
						$pagecontainer.append(' <tr id=ptjob' + i
								+ ' class="ptjob"><td>' + (i + 1) + '</td><td>'
								+ item.title + '</td><td>' + item.salary + '元/'
								+ item.salaryunit + '</td><td>'+item.mobile+'</td><td>'+item.time+'</td> <td>'
								+ item.createTime + '</td>' + temp + '</tr>');
					});
}

function ptSelect(type, place, endhour, endmin, isdel) {
	this.starthour = starthour;
	this.startmin = startmin;
	this.endhour = endhour;
	this.endmin = endmin;
	this.isdel = isdel;
}
function getcountriesbycity(url, $placeselect, parameter) {

	myAjax(url, parameter, function(data) {
		countries = data;
		$.each(data, function(index, item) {
			$placeselect.append('<a class="am-radius" id=' + item.daima
					+ ' onclick="changecontentcountry(' + item.daima + ')">'
					+ item.diming + '</a>&nbsp;');

		});

	});
}
function drawdiffrequsercontent($pagecontainer, data) {

	$.each(
					data,
					function(i, item) {
						var index = item.mobile;
						var id = item.id;
						var status = item.status;
						temp = '<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">'
								+ ' <button id=agreereq'
								+ i
								+ ' class=" agreereq am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span>  同意</button>'
								+ '  <button id=disagreereq'
								+ i
								+ ' class="disagreereq am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 不同意</button>'
								+ ' <button   id=userdetail'
								+ i
								+ ' class="am-btn userdetail am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 人员信息</button>'
								+ ' </div> </div></td>'

						$pagecontainer
								.append(' <tr class="itemline" id=itemline'
										+ i
										+ '><td><input type="checkbox" class="check" id=check'+i+' value='
										+ i+ '/></td><td>' + (i + 1)
										+ '</td><td>' + item.username
										+ '</td><td>' + item.gender
										+ '</td> <td>' + item.birthday
										+ '</td> <td>' + item.school
										+ '</td><td>' + item.createtime
										+ '</td>' + temp + ' </tr>');
					});

}
function drawdiffrequsercontentagree($pagecontainer, data) {

	$.each(data,
					function(i, item) {
						var index = item.mobile;
						var id = item.id;
						var status = item.status;
						

						$pagecontainer
								.append(' <tr class="itemline" id=itemline'
										+ i
										+ '><td>' + (i + 1)
										+ '</td><td>' + item.realname
										+ '</td><td>' + item.gender
										+ '</td> <td>' + item.birthday
										+ '</td> <td>' + item.mobile
										+ '</td> <td>' + item.email
										+ '</td> <td>' + item.school
										+ '</td><td>' + item.createtime
										+ '</td> </tr>');
					});

}

function getRootPath() {
	var curWwwPath = window.document.location.href;
	var pathName = window.document.location.pathname;
	var pos = curWwwPath.indexOf(pathName);
	var localhostPaht = curWwwPath.substring(0, pos);
	var projectName = pathName
			.substring(0, pathName.substr(1).indexOf('/') + 1);
	return (localhostPaht + projectName);
}

function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}